#include "funcselectpage.h"
#include "ui_funcselectpage.h"
#include "DBOperation/mysql.h"
#include "dataquerypage.h"

FuncSelectPage::FuncSelectPage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FuncSelectPage)
{
    ui->setupUi(this);
//    setBg();
    if(Constant::ShowFullScreen)
        this->showFullScreen();


    ui->bt_P2->setEnabled(true);
    myplayer = new QMediaPlayer;
    audioOutput=new QAudioOutput(this);
    audioOutput->setVolume(100);
    myplayer->setAudioOutput(audioOutput);
    myplayer->setSource(QUrl("qrc:/sound/welcome.mp3"));
    myplayer->play();


    mp1=new MeasurePage_P1();
    mp1->hide();

    sp=new SettingPage();
    sp->hide();
    dqp=new DataQueryPage();
    dqp->hide();

    mp2=new MeasurePage_P2();
    mp2->hide();


    threadWork=new ThreadWork();
    threadWork->start();
    connect(this,SIGNAL(Initial()),mp1,SLOT(InitialControl()));
    connect(this,SIGNAL(Initial()),mp2,SLOT(InitialControl2()));



    connect(threadWork,SIGNAL(sendData(double,double,double,double)),mp1,SLOT(getPPGData(double,double,double,double)));
    connect(threadWork,SIGNAL(sendHR2UI(unsigned char,int)),mp1,SLOT(getHRData(unsigned char,int)));
    connect(threadWork,SIGNAL(sendSPOX2UI(double,int)),mp1,SLOT(getSPOXData(double,int)));
    connect(threadWork,SIGNAL(sendRR2UI(int,int)),mp1,SLOT(getRRData(int,int)));
    connect(threadWork,SIGNAL(sendProgress2UI(int,int)),mp1,SLOT(getProgressData(int,int)));
    connect(threadWork,SIGNAL(sendOver(int)),mp1,SLOT(getOver(int)));

    connect(mp1,SIGNAL(sendStartOrStop(bool,int)),threadWork,SLOT(getStartOrStop(bool,int)));
    connect(mp1,SIGNAL(sendUserInfo2Thread(UserInfoBeab,int)),threadWork,SLOT(getUserInfo(UserInfoBeab,int)));



    connect(threadWork,SIGNAL(sendData(double,double,double,double)),mp2,SLOT(getPPGData(double,double,double,double)));
    connect(threadWork,SIGNAL(sendHR2UI(unsigned char,int)),mp2,SLOT(getHRData(unsigned char,int)));
    connect(threadWork,SIGNAL(sendSPOX2UI(double,int)),mp2,SLOT(getSPOXData(double,int)));
    connect(threadWork,SIGNAL(sendRR2UI(int,int)),mp2,SLOT(getRRData(int,int)));
    connect(threadWork,SIGNAL(sendProgress2UI(int,int)),mp2,SLOT(getProgressData2(int,int)));
    connect(threadWork,SIGNAL(sendOver2(int)),mp2,SLOT(getOver2(int)));

    connect(mp2,SIGNAL(sendStartOrStop2(bool,int)),threadWork,SLOT(getStartOrStop2(bool,int)));
    connect(mp2,SIGNAL(sendUserInfo2Thread2(UserInfoBeab,int)),threadWork,SLOT(getUserInfo(UserInfoBeab,int)));

    ui->bt_Scales->setVisible(false);
    ui->bt_UserManager->setVisible(false);
    ui->bt_help->setVisible(false);

    ui->bt_P2->setEnabled(!Constant::IsSingle);


}

FuncSelectPage::~FuncSelectPage()
{
    delete myplayer;
    delete audioOutput;
    delete mp1;
    delete mp2;
    delete sp;
    delete dqp;
    delete threadWork;
    delete ui;
}
/**
 * 功能：设置背景图片
 * @brief WelcomePage::setBg
 */
void FuncSelectPage::setBg()
{
    QPalette pal = this->palette();
    pal.setBrush(QPalette::Window,QBrush(QPixmap(":/images/funcSelectPage/funcsel_bg.png")));
    setPalette(pal);
}
void FuncSelectPage::paintEvent(QPaintEvent *event)
{
    //通过这种方式可以将图片平铺到窗口上
    //使用样式表可以很方便设置界面，而且非常高效，还能让界面和逻辑分离
    //不过在本例中由于是顶层窗口，所以直接设置样式表也不会显示。
    //所以样式表比较适合子窗口来使用。
    QPainter painter(this);
    painter.drawPixmap(rect(),QPixmap(":/images/funcSelectPage/funcsel_bg.png"),QRect());
}
void FuncSelectPage::on_bt_return_clicked()
{
    this->close();
}


void FuncSelectPage::on_bt_help_clicked()
{

}


void FuncSelectPage::on_bt_Scales_clicked()
{

}


void FuncSelectPage::on_bt_UserManager_clicked()
{

}


void FuncSelectPage::on_bt_dataQuery_clicked()
{
    dqp->show();
}


void FuncSelectPage::on_bt_P1_clicked()
{
    emit Initial();
    mp1->show();
}


void FuncSelectPage::on_bt_P2_clicked()
{
    emit Initial();
    mp2->show();
}


void FuncSelectPage::on_bt_setting_clicked()
{
    sp->show();

}

